import { createRouter, createWebHistory } from 'vue-router'



const routes = [
  {
    name: 'Home',
    path: '/home',
    component: () => import('../view/home/home.vue'),
    redirect: '/setting',
    children: [
      {
        name: 'setting',
        path: '/setting',
        component: () => import('../view/setting/setting.vue'),//数据设定
      },
      {
        name: 'basic',
        path: '/basic',
        component: () => import('../view/basic/basic.vue'),//舞蹈基本功
      },
      {
        name: 'impromptu',
        path: '/impromptu',
        component: () => import('../view/impromptu/impromptu.vue'),//即兴表演
      },
      {
        name: 'inspect',
        path: '/inspect',
        component: () => import('../view/inspect/inspect.vue'),//专业知识考察
      },
      {
        name: 'show',
        path: '/show',
        component: () => import('../view/show/show.vue'),//剧目展示
      },
      {
        name: 'collect',
        path: '/collect',
        component: () => import('../view/collect/collect.vue'),//数据汇总
      },
      {
        name: 'school',
        path: '/school',
        component: () => import('../view/school/school.vue'),//学校设定
      },
      {
        name: 'skill',
        path: '/skill',
        component: () => import('../view/skill/skill.vue'),//学校设定
      },
      {
        name: 'synthesize',
        path: '/synthesize',
        component: () => import('../view/synthesize/synthesize.vue'),//综合展示
      },
      {
        name: 'collect2025',
        path: '/collect2025',
        component: () => import('../view/collect2025/collect2025.vue.vue'),//数据汇总
      },
    ]
  },
  {
    name: 'login',
    path: '/',
    component: () => import('../view/login/login.vue')//登录
  },
  {
    name: 'upload',
    path: '/upload',
    component: () => import('../view/upload/upload.vue')//上传
  },
  {
    name: 'draw',
    path: '/draw',
    component: () => import('../view/draw/draw.vue')//抽奖
  },
  {
    name: 'music',
    path: '/music',
    component: () => import('../view/music/music.vue')//音乐
  },
  {
    name: 'routerpage',
    path: '/routerpage',
    component: () => import('../view/routerpage/routerpage.vue')//菜单设置
  },

]

const router = createRouter({
  history: createWebHistory(),
  routes
})


router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token')
  if (to.path == '/' || to.path == '/draw' || to.path == '/upload' || to.path == '/music' || '/routerpage') {
    next()
  } else {
    if (token) {
      next()
    } else {
      next('/')
    }
  }
})
router.afterEach((to, from) => {
  // console.log(to,from,next,'跳转后')
})

export default router